#ifndef TASK_MODEL_H
#define TASK_MODEL_H

#include "task.h"
#include <QTime>
#include <QtGui>
#include <QTimer>
#include <QStyledItemDelegate>

#define TaskDataVersion_0_1 651587458L

// ***************************** BaseTaskModel *******************************

class BaseTaskModel:public QAbstractItemModel{
	Q_OBJECT
public:
	BaseTaskModel(QObject *parent=0) ;
	virtual ~BaseTaskModel() {};
	virtual int	columnCount(
			const QModelIndex &parent=QModelIndex()) const;
	virtual int	rowCount(const QModelIndex &parent=QModelIndex()
			) const;
	virtual Qt::ItemFlags flags(const QModelIndex &index) const;
	virtual QVariant headerData(int column, Qt::Orientation orientation,
			int role) const;
	virtual QModelIndex 	index(int row, int column,
			const QModelIndex &parent=QModelIndex() ) const;
	virtual QModelIndex parent(const QModelIndex &index) const;
	virtual void 	startTask(const QModelIndex &index)=0;
	virtual void 	pauseTask(const QModelIndex &index)=0;
	virtual void 	stopTask(const QModelIndex &index)=0;
	virtual void 	deleteTasks(const QModelIndexList &indexes);
	virtual void	deleteDataTasks(const QModelIndexList &indexes);
	virtual BaseTask *getTask(const QModelIndex &index) 
		{return taskList[index.row()];};
	virtual void 	addTask(BaseTask *task);
	virtual void	loadTaskList();
	virtual void	saveTaskList();
public slots:
	virtual void taskDataChanged(BaseTask *task, int column) {};
protected:
	virtual void 	setupModelData() {};   
	QList<BaseTask *> taskList;
	QStringList columnHeaders;
	QString taskListFileName;
signals:
	void taskDeleted(BaseTask *task);
};

// **************************** DoneTaskModel *******************************

class DoneTaskModel:public BaseTaskModel{
	Q_OBJECT
public:
	DoneTaskModel(QObject *parent=0);
	QVariant data(const QModelIndex &index, int role) const;
	void startTask(const QModelIndex &index);
	void pauseTask(const QModelIndex &index);
	void stopTask(const QModelIndex &index);
	void increaseTask(const QModelIndex &index);
	void cutDownTask(const QModelIndex &index);
	void addTask(BaseTask *task);
protected:
	void setupModelData();
};

// *************************** UndoneTaskModel ******************************

class UndoneTaskModel:public BaseTaskModel{
	Q_OBJECT
public:
	UndoneTaskModel(QObject *parent=0);
	~UndoneTaskModel();
	QVariant data(const QModelIndex &index, int role) const;
	void startTask(const QModelIndex &index);
	void pauseTask(const QModelIndex &index);
	void stopTask(const QModelIndex &index=QModelIndex());
	void increaseTask(const QModelIndex &index) ;
	void cutDownTask(const QModelIndex &index) ;
public slots:
	void taskDataChanged(BaseTask *task, int column);
	void loopUpdate();
protected:
	void setupModelData();
	QTimer *timer;
signals:
	void taskCompleted(BaseTask *task);
};

// ************************ UndoneTaskViewDelegate ***************************

class UndoneTaskViewDelegate : public QStyledItemDelegate
{
	 Q_OBJECT
public:
	 UndoneTaskViewDelegate(QObject *parent=0) : QStyledItemDelegate(parent) {};
	 void paint(QPainter *painter, const QStyleOptionViewItem &option,
					   const QModelIndex &index ) const;
};

	

#endif /* TASK_MODEL_H */
